﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PsTFS.Commandes.Add;

namespace PsTFS.Objects
{
    /// <summary>
    /// Gestion des erreur de PsTSF
    /// </summary>
    public class Error
    {
        /// <summary>
        /// Variable de classe pour le singleton
        /// </summary>
        private static Error m_Error;

        /// <summary>
        /// Singleton pour une unique instance
        /// </summary>
        /// <returns></returns>
        public static Error GetInstance()
        {
            if (m_Error == null)
                m_Error = new Error();
            return m_Error;
        }

        /// <summary>
        /// Récupère le numéros d'erreur par rapport à son emplacement
        /// </summary>
        /// <returns></returns>
        public string GetError(object obj)
        {
            var v = from o in lsError
                    where o.ObjectErr == obj.GetType()
                    select o;
            if (v.ToList<Err>().Count < 0)
                return v.ToList<Err>()[0].Numero + " : " + v.ToList<Err>()[0].Description;
            else
                return "Error with " + obj.ToString();
        }
        
        List<Err> lsError = new List<Err>();

        /// <summary>
        /// Permet de charger les erreurs
        /// </summary>
        /// <remarks>
        /// Number 1 :
        /// 1 = Error CMDLET
        /// 2 = Error Methode
        /// Number 2 and 3:
        /// 00 : not cdmlet
        /// 01 : Cmdlet Add
        /// 02 : Cmdlet Clear
        /// 03 : Cmdlet Get
        /// 04 : Cmdlet Out
        /// 05 : Cmdlet Remove
        /// 06 : Cmdlet Set
        /// </remarks>
        private void LoadData()
        {
            lsError.Add(new Err() { Description = "Error add-branche", Numero = "PS10101", ObjectErr = typeof(Add_Branch) });
            lsError.Add(new Err() { Description = "Error add-files", Numero = "PS10101", ObjectErr = typeof(Add_Files) });
            lsError.Add(new Err() { Description = "Error add-label", Numero = "PS10101", ObjectErr = typeof(Add_Label) });
            lsError.Add(new Err() { Description = "Error add-memberproject", Numero = "PS10101", ObjectErr = typeof(Add_MemberProject) });
            lsError.Add(new Err() { Description = "Error add-Project", Numero = "PS10101", ObjectErr = typeof(Add_Project) });
            lsError.Add(new Err() { Description = "Error add-QualityBuild", Numero = "PS10101", ObjectErr = typeof(Add_QualityBuild) });
        }
    }
}
